IF EXISTS (SELECT * FROM DBO.SYSOBJECTS WHERE NAME = 'sp_SEARCHTHANNHAN')
BEGIN
	DROP PROC sp_SEARCHTHANNHAN
END
GO
CREATE PROC sp_SEARCHTHANNHAN
	@maNV	NVARCHAR(20),
	@tenTN	NVARCHAR(40)
AS
BEGIN
	IF(@maNV='' AND @tenTN='')
	BEGIN
		SELECT * FROM THANNHAN
	END
	IF(@maNV<>'' AND @tenTN='')
	BEGIN
		SELECT * FROM THANNHAN WHERE MA_NVIEN = @maNV
	END
	IF(@maNV='' AND @tenTN<>'')
	BEGIN
		SELECT * FROM THANNHAN WHERE TENTN = @tenTN
	END
	IF(@maNV<>'' AND @tenTN<>'')
	BEGIN
		SELECT * FROM THANNHAN WHERE TENTN = @tenTN OR MA_NVIEN =@maNV
	END
END

exec sp_SEARCHTHANNHAN '',''